1881C - Perfect Square - CodeForces Solution


brute force implementation

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>

using namespace std;
using LL = long long;
using C = char;
using I = int;
using D = double;
using LD = long double;
using S = string;
using B = bool;
using ULL = unsigned long long;
using G = greater<I>;

#define endl "\n"
#define dbg(x...)
#define fr(i,a,n) for(i = a;i<n;++i)
#define fl(i,n) fr(i,0,n)
#define testno int t; cin>>t; while(t--){solve();}
#define LMAX (LL)2e18
#define LMIN (LL)-2e18
#define yes cout<<"YES"
#define no cout<<"NO"
    
typedef vector<I> VI;
typedef vector<LL> VL;
typedef vector<C> VC;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<pair<I,I>> VP;
typedef priority_queue<I, VI, G> PQ;
typedef priority_queue<I> PI;
typedef unordered_map<I, I>UMI;
typedef unordered_map<LL, I>UMLI;
typedef unordered_map<LL, LL>UML;
typedef unordered_map<I, VI>UVI;
typedef unordered_map<I, PQ> UPQ;
typedef map<LL, LL>MPL;
typedef map<I, I>MPI;
typedef set<I>SI;

#define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

LL gcd(LL a, LL b){
    return (a%b==0)? b : gcd(b, a%b);
}
// bitset<10000007> prime;
// bitset<5000003> chk;
// auto st_prime = [](){
//     prime.set(0); prime.set(1);
//     for(int i=2; i*i<=1e7+7; ++i){
//         if(!prime[i]){
//             for(int j = i*i;j<=1e7+7; j+=i){
//                 prime.set(j);
//             }
//         }
//     }
// };
// vector<int>store(1e9, 0);
// VVI tree;
// VI ver_conn;
// I chk = (1<<31)-1;

void solve(){
    I n; cin>>n;
    vector<vector<C>> vc(n, vector<C>(n));
    I i, j;
    fl(i, n){
        fl(j, n){
            cin>>vc[i][j];
        }
    }
    LL cnt{};
    fl(i, n>>1){
        I k = n-i-1;
        fr(j, i, k){
            C mx = vc[i][j];
            mx = max(mx, max(vc[j][k], max(vc[k][k-(j-i)], vc[k-(j-i)][i])));
            cnt += mx-vc[i][j];
            cnt += mx-vc[j][k];
            cnt += mx-vc[k][k-(j-i)];
            cnt += mx-vc[k-(j-i)][i];
            // vc[i][j] = mx;
            // vc[j][k]=mx;
            // vc[k][k-(j-i)]=mx;
            // vc[k-(j-i)][i]=mx;
        }
    }
    cout<<cnt<<endl;
    // fl(i, n){
    //     fl(j, n){
    //         cout<<vc[i][j];
    //     }
    //     cout<<endl;
    // }
    // cout<<endl;
}
int32_t main(){
    fastio; 
    // st_prime();
    testno;
    // solve();
    // cout<<flush;
    return 0;
}             


Comments

Submit
0 Comments
More Questions

115A - Party
746B - Decoding
1424G - Years
1663A - Who Tested
1073B - Vasya and Books
195B - After Training
455A - Boredom
1099A - Snowball
1651D - Nearest Excluded Points
599A - Patrick and Shopping
237A - Free Cash
1615B - And It's Non-Zero
1619E - MEX and Increments
34B - Sale
1436A - Reorder
1363C - Game On Leaves
1373C - Pluses and Minuses
1173B - Nauuo and Chess
318B - Strings of Power
1625A - Ancient Civilization
864A - Fair Game
1663B - Mike's Sequence
448A - Rewards
1622A - Construct a Rectangle
1620A - Equal or Not Equal
1517A - Sum of 2050
620A - Professor GukiZ's Robot
1342A - Road To Zero
1520A - Do Not Be Distracted
352A - Jeff and Digits